package com.uenpay.im.ui.old.activity.funds;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.uenpay.im.R;

import java.text.MessageFormat;
import java.util.ArrayList;

/**
 * @author SL
 * @copyRight http://www.qiyunxin.com
 * @E-mail:
 * @date 创建时间：2016-5-10 下午7:51:33
 * @version 1.0
 * @function 经费支出适配器
 */
public class FundsCostAdapter extends BaseAdapter {

	private Context mContext;
	private ArrayList<FundsOutEntity> arrayList;

	public FundsCostAdapter(Context _Context,
			ArrayList<FundsOutEntity> _ArrayList) {
		arrayList = _ArrayList;
		mContext = _Context;
	}

	@Override
	public int getCount() {
		return arrayList == null ? 0 : arrayList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return arrayList == null ? null : arrayList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		FundsCostViewHodler viewHodler = null;
		if (arg1 == null) {
			viewHodler = new FundsCostViewHodler();
			arg1 = View
					.inflate(mContext, R.layout.item_funds_cost_layout, null);
			viewHodler.content = (TextView) arg1.findViewById(R.id.content_tv);
			viewHodler.date = (TextView) arg1.findViewById(R.id.date_tv);
			viewHodler.amount = (TextView) arg1.findViewById(R.id.amount_tv);
			arg1.setTag(viewHodler);
		} else {
			viewHodler = (FundsCostViewHodler) arg1.getTag();
		}

		viewHodler.content.setText(arrayList.get(arg0).content);
		viewHodler.date.setText(arrayList.get(arg0).createtime);
		viewHodler.amount.setText("-"
				+ MessageFormat.format(
						mContext.getResources().getString(R.string.red_size),
						arrayList.get(arg0).amount));
		return arg1;
	}

	private class FundsCostViewHodler {
		private TextView content, date, amount;
	}
}
